<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/css/scroll.css}">
    <style>
        body, html {
            height: 100vh;
        }

        /* table 样式 */
        table {
            border-top: 1px solid #ccc;
            border-left: 1px solid #ccc;
        }

        table td,
        table th {
            border-bottom: 1px solid #ccc;
            border-right: 1px solid #ccc;
            padding: 3px 5px;
        }

        table th {
            border-bottom: 2px solid #ccc;
            text-align: center;
        }

        /* blockquote 样式 */
        blockquote {
            display: block;
            border-left: 8px solid #d0e5f2;
            padding: 5px 10px;
            margin: 10px 0;
            line-height: 1.4;
            font-size: 100%;
            background-color: #f1f1f1;
        }

        /* code 样式 */
        code {
            display: inline-block;
            *display: inline;
            *zoom: 1;
            background-color: #f1f1f1;
            border-radius: 3px;
            padding: 3px 5px;
            margin: 0 3px;
        }

        pre code {
            display: block;
        }

        /* ul ol 样式 */
        ul, ol {
            margin: 10px 0 10px 20px;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <nav style="margin: 10px 0; padding-bottom:5px;border-bottom: 1px dashed darkgray;">
    <span class="layui-breadcrumb">
        <a th:href="@{/admin/home}">首页</a>
        <a>办公管理</a>
        <a>
            <cite>信息一览</cite>
        </a>
    </span>
    </nav>


    <div class="layui-row">
        <div class="layui-col-md8" style="margin-bottom: 15px;">
            <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="page(-1)">
                <i class="layui-icon">&#xe65a;</i>
                Prev
            </button>
            <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="page(1)">
                <i class="layui-icon">&#xe65b;</i>
                Next
            </button>
        </div>

        <div class="layui-col-md4">

        </div>
    </div>
    <div class="layui-row">
        <p style="text-align: left;color: darkgray;">共检索到数据
            <span style="color: red;" id="totalShow"></span>
            条,当前第
            <span style="color: red;" id="currentPageShow"></span> 页 ,
            每页显示
            10
            条 。
        </p>
    </div>
    <div>
        <table class="layui-table layui-table-page my-table" style="cursor: pointer;">
            <thead>
            <tr>
                <th style="text-align: center;">标题</th>
                <th style="text-align: center;">时间</th>
            </tr>
            </thead>
            <tbody id="tableData">
            </tbody>
        </table>
    </div>

</div>
<script th:src="@{/js/jquery-3.4.1.js}"></script>
<script th:src="@{/js/utils.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script th:src="@{/layui/lay/modules/element.js}"></script>
<script th:src="@{/layui/lay/modules/table.js}"></script>

<script type="text/javascript">

    var currentPage = 1;
    var pageSize = 20;
    var total = 0;
    var hasNext = false;
    var noticeList = "";
    var tableData = $("#tableData");

    function getAdvice(currentPage, pageSize) {
        $.post("../../advice/list?currentPage=" + currentPage + "&pageSize=" + pageSize, function (resp) {
            hasNext = resp.data.hasNext;
            total = resp.data.total;
            noticeList = resp.data.noticeList;
            //console.log(noticeList);

            var dataStr = ""
            for (var i = 0; i < noticeList.length; i++) {

                dataStr += "<tr onclick='go(\"" + noticeList[i].id + "\")'>\n" +
                    "                <td>" + noticeList[i].title + "</td>\n" +
                    "                <td style='width: 300px;text-align: center;'>" + dateFormat(noticeList[i].created) + "</td>\n" +
                    "            </tr>"
            }
            tableData.html(dataStr);


            $("#totalShow").text(total);
            $("#currentPageShow").text(currentPage);
        })
    }


    function page(d) {
        if (d === -1) {
            if (currentPage <= 1) {
                layer.msg("已经是第一页了", {icon: 5})
                return false;
            }
            currentPage = currentPage - 1;
            getAdvice(currentPage, pageSize);

        } else {
            if (!hasNext) {
                layer.msg("已经是第最后一页了", {icon: 5})
                return false;
            }

            currentPage = currentPage + 1;
            getAdvice(currentPage, pageSize);

        }

    }

    function go(id) {
        var i = 0;
        for (; i < noticeList.length; i++) {
            if (id === noticeList[i].id)
                break;
        }
        console.log(noticeList[i].content);
        layer.open({
            type: 1,
            title: "查看通知：" + noticeList[i].title,
            closeBtn: 1,
            maxmin: false, //开启最大化最小化按钮
            area: ['893px', '550px'],
            shadeClose: true,
            content: noticeList[i].content
        });
    }


    $(function () {
        getAdvice(currentPage, pageSize);
    })
</script>
</body>
</html>